#include<iostream>
using namespace std;
char arr[65][20];
int main()
{
	int n, w, s;
	char ch;;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	cin >> w >> ch >> s;
	int count = 0;
	w = w - 2;
	while (count < n) {
		for (int i = 0; i < s; i++) {
			w = (++w) % n;
			if (arr[w][18] == '1') {
				i--;
			}
		}
		cout << arr[w] << endl;
		arr[w][18] = '1';
		count++;
	}
	return 0;
}